//
//  WBNavigationController.m
//  WeiBo
//
//  Created by ChenJunWen on 2017/11/29.
//  Copyright © 2017年 CJW. All rights reserved.
//

#import "WBNavigationController.h"
#import "WBBaseViewController.h"

@interface WBNavigationController ()

@end

@implementation WBNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationBar.hidden = YES;
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    
    if (self.childViewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
        
        if ([viewController isKindOfClass:[WBBaseViewController class]]) {
            WBBaseViewController *vc = (WBBaseViewController *)viewController;
            NSString *title = @"返回";
            if (self.childViewControllers.count == 1) {
                title = self.childViewControllers.firstObject.title;
            }
            [vc setupUI]; // 创建customNavItem
            vc.customNavItem.leftBarButtonItem = [UIBarButtonItem setTitle:title fontSize:16 target:self action:@selector(popToParents) isBack:YES];
        }
    }
    
    [super pushViewController:viewController animated:YES];
}

- (void)popToParents {
    [self popViewControllerAnimated:YES];
}


@end
